var config = require('../config')
var log = require('./../libs/log')
var bodyParser = require('body-parser')
var session = require('express-session')
var cookieParser = require('cookie-parser');
var RedisStrore = require('connect-redis')(session);

var express = require('express')
var app = express()

log.use(app)

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }));
app.use(session({
     secret: 'kamisama',
     name: 'eagleeye',
     cookie: {maxAge: Number.MAX_VALUE },
     resave: true,
     saveUninitialized: true,
    //  redis存储session
     store : new RedisStrore(config.redis_host)
}));

app.use(function(err, req, res, next) {
  // error handling logic
  console.error(err.stack);
  res.status(500).send('Something broke!');
});


app.get('/dist/build.js', function(req,res,next){
    res.sendFile(process.cwd() + '/dist/build.js')
})

app.get('/', function(req,res){
    res.sendFile(process.cwd() + '/index.html')
})

module.exports = app
